home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 6 / coreaids.zip / FILE_MOD.ASM < prev    next >
Assembly Source File  |  1987-06-26  |  5KB  |  179 lines

  1. ;    DESC:    Replaces one string with another string in a         V1.00
  2. ;        series of files of less than 40,000 bytes each.
  3. ;    IN:    *search string
  4. ;        *replacement string
  5. ;        *filename.ext with wildcards allowed.
  6. ;    OUT:    *all files meeting the file specification and having
  7. ;        a search string matching the input one have had the text
  8. ;        replaced with the replacement string.
  9. ;    SAMPLE:    FILE_MOD search string,replacement string,*.ASM
  10. ;    ####################################################################
  11.  
  12. FIL_MODD Segment Para Public 'DATA'
  13.         DW    0            ;help message.
  14.         DW    0
  15.         DD    MHELP
  16.         DW    EHELP
  17. MHELP        DB    0DH,0AH,'               '
  18.         DB    'DESC:   Replaces one string with another string'
  19.         DB    0DH,0AH,'               '
  20.         DB    'in a series of files of less than 40,000 bytes each.'
  21.         DB    0DH,0AH,'               '
  22.         DB    'IN:     *search string'
  23.         DB    0DH,0AH,'               '
  24.         DB    '        *replacement string'
  25.         DB    0DH,0AH,'               '
  26.         DB    '        *filename.ext with wildcards allowed.'
  27.         DB    0DH,0AH,'               '
  28.         DB    'OUT:    *all files meeting the file specification'
  29.         DB    0DH,0AH,'               '
  30.         DB    'and having a search string matching the input one'
  31.         DB    0DH,0AH,'               '
  32.         DB    'have had the text replaced with the replacement'
  33.         DB    0DH,0AH,'               '
  34.         DB    'string.'
  35.         DB    0DH,0AH,'               '
  36.         DB    'SAMPLE: FILE_MOD search string,'
  37.         DB    0DH,0AH,'               '
  38.         DB    'replacement string,*.ASM'
  39.         DB    0DH,0AH,'               '
  40. EHELP        DB    0
  41.  
  42. SIZEHI        DW    0            ;high word of file size.
  43. SIZELO        DW    0            ;low word of file size.
  44.  
  45.  
  46. INHNDL        DW    0            ;input file handle.
  47.  
  48. RSEG        DW    0            ;replacement string info.
  49. ROFF        DW    0
  50.  
  51. SSEG        DW    0            ;search string info.
  52. SOFF        DW    0
  53. SLEN        DW    0
  54.  
  55. BUFFER        DB    40000 Dup(0)        ;entry buffer.
  56. FIL_MODD Ends
  57.  
  58.     Extrn    SRCH_FIL:Near            ;locate files matching the
  59.                         ;search string.
  60.     Extrn    ERRORMSG:Near            ;prints error exit messages.
  61.     Extrn    OPEN:Near                ;opens file.
  62.     Extrn    WRITE:Near            ;writes to a file.
  63.     Extrn    READ:Near            ;reads from data file.
  64.     Extrn    SRCH_NXT:Near            ;searches for next match.
  65.     Extrn    CLOSE:Near            ;closes data files.
  66.     Extrn    HELP:Near            ;provides help information.
  67.     Extrn    REPLACE:Near            ;replace strings.
  68.     Extrn    PARM_BRK:Near            ;breaks up  parameter strings.
  69.  
  70. FIL_MODC    Segment Para Public 'CODE'
  71.     Assume CS:FIL_MODC,DS:FIL_MODD
  72.  
  73.     Include    CALLM.MAC            ;macro file which allows
  74.                         ;input and output of
  75.                         ;parameters to subroutines.
  76.     DW    0,0,0,180,0,0,0
  77.  
  78.                         ;notice.
  79.     DB    'FILE_MOD - V1.00, Copyright 1987, CoreTechs   ',0DH,0AH
  80.  
  81. FILE_MOD    Proc    Far            ;main procedure.
  82.  
  83.     Push    DS                ;store return address.
  84.     Xor    AX,AX
  85.     Push    AX
  86.  
  87.     Mov    BX,DS                ;save initial data segment.
  88.  
  89.     Mov    AX,FIL_MODD            ;assign data segment location.
  90.     Mov    DS,AX
  91.  
  92.     Callm    HELP,<BX,AX>,<ES,BX,CX>        ;get DOS data line
  93.                         ;specifying files on which
  94.                         ;to make listing.
  95.  
  96.     Callm    PARM_BRK,<ES,BX,CX>,<CX>    ;break up multiple params.
  97.  
  98.     Cmp    CX,3                ;if three params., OK.
  99.     Jz    CONT0
  100.  
  101.     Callm    ERRORMSG,<22>,            ;wrong number of params.
  102.  
  103. CONT0:    Pop    ES                ;recover third param.
  104.     Pop    BX
  105.     Pop    CX
  106.  
  107.     Mov    CX,20H                ;locate first filename.
  108.     Callm    SRCH_FIL,<ES,BX>,<AX,AX,SIZELO,SIZEHI,ES,BX,CX>
  109.     Jcxz    ERROR1                ;exit if no matching files.
  110.  
  111.     Jmp    CONT2
  112.  
  113. ERROR1:    Callm    ERRORMSG,<2>,            ;display no File(s) found.
  114.  
  115. CONT2:    Pop    RSEG
  116.     Pop    ROFF
  117.     Pop    AX
  118.  
  119.     Pop    SSEG
  120.     Pop    SOFF
  121.     Pop    SLEN
  122.  
  123. CONT3:    Cmp    SIZEHI,0            ;if file is greater then
  124.     Ja    TNXT                ;40,000 bytes skip.
  125.  
  126.     Cmp    SIZELO,40000
  127.     Ja    TNXT
  128.     Jmp    CONT1
  129.  
  130. TNXT:    Jmp    SNXT
  131.  
  132. CONT1:    Callm    OPEN,<ES,BX,0>,<INHNDL>        ;open input file.
  133.  
  134.                         ;read entry.
  135.     Callm    READ,<INHNDL,40000,DS,<OFFSET BUFFER>>,<CX>
  136.  
  137.     Callm    CLOSE,<INHNDL>,            ;close input file.
  138.  
  139.     Mov    DX,OFFSET BUFFER        ;initialize buffer pointer.
  140. P1:    Callm    REPLACE,<RSEG,ROFF,0,DS,DX,SLEN,SSEG,SOFF>,<AX,DX>
  141.  
  142.     Cmp    AX,0                ;check for all replacements
  143.     Jz    CHK1                ;completed.
  144.  
  145.     Sub    DX,OFFSET BUFFER        ;determine if end of file
  146.     Cmp    DX,SIZELO            ;is passed.
  147.     Jae    CHK3
  148.  
  149.     Add    DX,OFFSET BUFFER
  150.     Jmp    P1
  151.  
  152. CHK1:    Cmp    DX,0
  153.     Jz    CHK3
  154.  
  155.     Sub    DX,OFFSET BUFFER        ;determine if end of file
  156.     Cmp    DX,SIZELO            ;is passed.
  157.     Jae    CHK3
  158.  
  159.     Add    DX,OFFSET BUFFER
  160.     Jmp    P1
  161.  
  162. CHK3:    Callm    OPEN,<ES,BX,1>,<INHNDL>        ;open input file to write.
  163.  
  164.                         ;write entry to file.
  165.     Callm    WRITE,<INHNDL,CX,DS,<OFFSET BUFFER>>,<AX>
  166.  
  167.     Callm    CLOSE,<INHNDL>,            ;close input file.
  168.  
  169. SNXT:    Mov    CX,20H                ;locate first filename.
  170.     Callm    SRCH_NXT,<ES,BX>,<AX,AX,SIZELO,SIZEHI,ES,BX,CX>
  171.     Jcxz    ERROR2                ;exit if no more files.
  172.     Jmp    CONT3                ;return to start of loop.
  173.  
  174. ERROR2:    Callm    ERRORMSG,<18>,            ;display no More Files(s).
  175.  
  176. FILE_MOD    Endp
  177. FIL_MODC    Ends
  178.     End    FILE_MOD
  179.